<template>
    <div :style="styles" :id="id"></div>
</template>
    
<script>
import * as echarts from 'echarts/core';
import {BarChart, PieChart} from 'echarts/charts';
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent,
  DatasetComponent
} from 'echarts/components';
import {
  CanvasRenderer
} from 'echarts/renderers';
echarts.use(
  [
    TitleComponent,
    TooltipComponent,
    GridComponent,
    BarChart,
    PieChart,
    LegendComponent,
    DatasetComponent,
    CanvasRenderer
  ]
);
export default {
    name: 'ChartBar2',
    components: {
    },
    props: {
        id:{
            default: 'myChart2'
        },
        styles: {
            default: { width: '100%', height: '100%' }
        },
        bottomList: {
            default: ['带看次数', '房源跟进', '客源跟进', '新增房源', '新增客源']
        },
        countList: {
            default: [13, 20, 5, 15, 11]
        },
        title: {
            default: '二手房TOP5'
        },
    },
    data() {
        return {
        }
    },
    mounted() {
        this.draw();
    },
    methods: {
        draw() {
            // 基于刚刚准备好的 DOM 容器，初始化 EChart 实例
            let myChart = echarts.init(document.getElementById(this.id))
            // 绘制图表
            myChart.setOption({
                title: {
                    text: this.title,
                    left: "center",
                    top:'5%'
                },
                grid: {
                    left: "20%",
                    // right: "0px",
                    // top:"0%",
                    bottom: "15%"
                },
                tooltip: {},
                xAxis: {
                },
                yAxis: { data: this.bottomList },
                series: [{
                    name: '数量',
                    type: 'bar',
                    data: this.countList,
                    itemStyle: {
                        borderRadius: 5,
                        color: '#6698ff',
                        borderWidth: 2
                    },
                    barWidth: '60%'
                }]
            });
        },
    },
    watch: {
    },
    computed: {
    }

}
</script>
    
<style scoped>
</style>